import { eventWithTime } from "@rrweb/types";
import { record } from "rrweb";

export let eventsMatrix: eventWithTime[][] = [[]];

export default () => {
  record({
    emit(event: eventWithTime, isCheckout?: boolean) {
      // isCheckout 是一个标识，告诉你重新制作了快照
      if (isCheckout) {
        eventsMatrix.push([]);
        if (eventsMatrix.length > 16) {
          eventsMatrix = eventsMatrix.slice(12);
        }
      }
      const lastEvents = eventsMatrix[eventsMatrix.length - 1];
      lastEvents.push(event);
    },
    checkoutEveryNms: 0.5 * 60 * 1000, // 每 30s 重新制作快照
  });
};
